<template>
  <div class="header">
    <li v-for="film in films" :key="film.filmId">
      <!-- 订单首行 -->
      <div>
        <van-cell is-link @click.stop="this.$router.push('shopDetail')">
          <div class="hedss">
            <!-- 头像 -->
            <van-image
              round
              width="0.4rem"
              height="0.4rem"
              :src="film.imgUrl"
            />
            <!-- 店铺 -->
            <span class="dpTop">{{ film.shopName }}</span>
          </div>
        </van-cell>
      </div>
      <!-- 订单信息类 -->
      <div class="message">
        <van-cell>
          <!-- 菜的信息 -->
          <p class="food">
            <span>{{ film.productName }}</span
            ><span>x{{ film.productCount }}</span>
          </p>
          <!-- 时间和付款信息 -->
          <p class="timeGo" @click="getInforId(film.id)">
            <span>{{ film.orderTime }}</span
            ><span>实付¥{{ film.totalPrice }}</span>
          </p>
        </van-cell>
      </div>
      <p class="foots" @click="getInforId(film.id)">
        <span>{{ film.orderStatusStr }}</span>
        <van-button class="btns" type="default" @click.stop="removeTodo(film)"
          >删除</van-button
        >
        <van-button
          v-if="film.switch"
          class="repetition"
          type="default"
          @click.stop="this.$router.push('shopDetail')"
          >再来一单</van-button
        >
      </p>
    </li>
    <div class="model" v-if="isShow">
      <div class="content">
        <p>确认删除该订单?</p>
        <button @click="isShow = false">取消</button>
        <button @click="confirm(prepareRemoveId)">确定</button>
      </div>
    </div>
    <div class="ffd">没有更多了.....</div>
    <van-popup v-model:show="show">我是店铺内容</van-popup>
  </div>
</template>

<script>
import { defineComponent } from 'vue'
import { ref } from 'vue'
import axios from 'axios'
import { mapState, mapMutations } from 'vuex'
export default defineComponent({
  data() {
    return {
      films: [],
      isShow: false,
      prepareRemoveId: ''
    }
  },
  computed: {
    ...mapState(['infoId'])
  },
  async created() {
    let res = await axios({
      //?_page=1&_limit=3
      url: 'http://localhost:5000/order'
    })
    // console.log(res.data)
    this.films = res.data.orders
  },
  methods: {
    ...mapMutations(['increment']),
    removeTodo(film) {
      this.isShow = true
      this.prepareRemoveId = film.id
    },
    confirm(prepareRemoveId) {
      this.films = this.films.filter((_) => _.id !== prepareRemoveId)
      this.isShow = false
    },
    getInforId(filmId) {
      this.$router.push('orderdetail')
      this.increment(filmId)
      // console.log('id-', this.infoId)
    }
  },
  setup() {
    const show = ref(false)
    const showPopup = () => {
      show.value = true
    }
    return {
      show,
      showPopup
    }
  }
})
</script>

<style lang="scss" scoped>
.header {
  background-color: #eee;
  font-family: 'PingFangSC-Regular', 'Hiragino Sans GB', Arial, Helvetica,
    '宋体', sans-serif;
}
li {
  margin-bottom: 10px;
  position: relative;
  background-color: #fff;
  padding-left: 0.01rem;
  border-top: 1px solid #d7d7d7;
  border-bottom: 1px solid #d7d7d7;
  list-style: none;
}
// 店铺top设置
.dpTop {
  margin-left: 0.1rem;
  font-size: 0.18rem;
}
// 订单center文字
.food {
  font-size: 0.16rem;
}
.food span:nth-child(2) {
  float: right;
}
//订单时间信息设置
.timeGo span:nth-child(1) {
  color: #999;
  font-size: 0.12rem;
}
.timeGo span:nth-child(2) {
  float: right;
}
.hedss {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.message {
  border-top: 0.01rem solid #d7d7d7;
}
//底部p设置
.header .foots {
  margin-bottom: 0.1rem;
  background-color: #fff;
  border-top: 1px solid #d7d7d7;
  display: flex;
  align-items: center;
  margin-left: 0.12rem;
  justify-content: space-between;
  color: #999;
  font-size: 0.16rem;
  height: 0.4rem;
}
.header .foots span:nth-child(1) {
  flex: 1;
}
.foots .btns {
  // border: 0.01rem solid #999;
  box-shadow: #858687 0rem 0rem 0.02rem;
  height: 0.3rem;
  width: 0.68rem;
  // margin-right: 0.15rem;
  border-radius: 0.05rem;
  margin-top: 0.12rem;
  color: #858687;
  align-items: center;
  font-size: 0.15rem;
  margin-right: 0.2rem;
}
.foots .repetition {
  height: 0.35rem;
  width: 0.9rem;
  display: inline-block;
  float: right;
  margin-top: 0.12rem;
  padding: 0 0.05rem;
  color: #333;
  border: solid 1px #ffd161;
  margin-right: 0.05rem;
  border-radius: 0.03rem;
  background-color: #ffd161;
}
.ffd {
  height: 1.2rem;
  text-align: center;
  color: #666460;
  font-size: 0.15rem;
}
//删除框
.model {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10;
}
.model .content {
  width: 3.4rem;
  height: 1.2rem;
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  text-align: center;
  border-radius: 0.11rem;
  overflow: hidden;
}
.model .content p {
  height: 0.75rem;
  align-items: center;
  display: flex;
  justify-content: center;
}
.model .content button {
  height: 0.45rem;
  width: 1.69rem;
  background-color: #fff;
  border: none;
}
// .model .content span {
//   border-top: 0.01rem solid #999;
//   height: 50%;
//   display: inline-block;
// }
// .model .content span:nth-of-type(1) {
//   border-right: 1px solid #999;
//   height: 50%;
//   display: inline-block;
// }
</style>
